package com.pro.controller;

import com.pro.pojo.JsCourseRecord;
import com.pro.pojo.JsonData;
import com.pro.service.JsMicroRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName:JsMicroRecordController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/12/7 下午 4:21
 * @Author: WYH
 */
@Controller
@RequestMapping("/microEx")
public class JsMicroRecordController {

    @Autowired
    private JsMicroRecordService jsMicroRecordService;

    @RequestMapping("/getAllMicRecord")
    @ResponseBody
    public JsonData getAllMicRecord(String result) {
        result = result != null && result != "" ? "%"+result+"%" : "%%";
        List<JsCourseRecord> allMicRecord = jsMicroRecordService.getAllMicRecord(result);
        Integer count = jsMicroRecordService.count(result);
        return allMicRecord != null ? JsonData.buildSuccess(allMicRecord,count) : JsonData.buildError("数据格式异常");
    }

    @RequestMapping("/selectCont")
    @ResponseBody
    public JsonData count(String result){
        result = result!="" ? "%"+result+"%":"%%";
        Integer integer = jsMicroRecordService.count(result);
        return integer >= 0 ? JsonData.buildSuccess(integer): JsonData.buildError("服务端错误");
    };

    @RequestMapping("/getMoMicRecord")
    @ResponseBody
    public JsonData getMoMicRecord(String artcleTitle, String artcleCategroyName, String trueName) {
        artcleTitle = artcleTitle != null && artcleTitle != "" ? "%"+artcleTitle+"%" : "%%";
        artcleCategroyName = artcleCategroyName != null && artcleCategroyName != "" ? "%"+artcleCategroyName+"%" : "%%";
        trueName = trueName != null && trueName != "" ? "%"+trueName+"%" : "%%";
        List<JsCourseRecord> moMicRecord = jsMicroRecordService.getMoMicRecord(artcleTitle, artcleCategroyName, trueName);
        Integer integer = jsMicroRecordService.countMo(artcleTitle, artcleCategroyName, trueName);
        return moMicRecord != null ? JsonData.buildSuccess(moMicRecord,integer) : JsonData.buildError("数据格式异常");
    }

    @RequestMapping("/updateMicro")
    @ResponseBody
    public JsonData updateMicro(JsCourseRecord jsCourseRecord) {
        Boolean aBoolean = jsMicroRecordService.updateMicro(jsCourseRecord);
        return aBoolean != false ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("数据格式异常");
    }
}
